Accusoft.OCRXpress.Java
Get Result Elements (Word, Character, Textlines, etc.)

The Results Manager is a collection of Get functions that allow certain Result objects to be accessed. For more information, see Results Manager.

A result element can be any of the Result objects returned from recognition.

The call to recognizeToMemory() returns a Document object that serves as the base result with which to access all other result elements.

Copy Code
// Get the base document object.
Document document = ocrXpressObject.recognizeToMemory(recognitionParametersObject, bufferedImg);

With this object, applications can get a reference to any descendant element of a given result element. The below code example will show how to get a particular word and then the area (or location) for that word:

Copy Code
// Get the fifth word of the fifth region in the document
Word word = document.getRegions().get(4).getWords().get(4);
// Get where the word occurs in the image:
int leftSideOfWord = word.getArea().getLeft();
int rightSideOfWord = word.getArea().getRight();
// Calculate the width (in pixels) of the word
int wordWidth = rightSideOfWord – leftSideOfWord;

The below code example shows how to count the number of words in the first line of text in a document.

Copy Code
// Get the first text line in the document
TextLine txtLine = document.getTextLine().get(0);
// Get where the word occurs in the image:
int numberOfWords = txtLine.getWords().size();

In order to copy text out of OCR Xpress for Java, the application simply has to call the getText() method of a result, or use the toString() method.

In the following example code, the result element being accessed is the fifth word of the fifth region in a document we accessed above.

Copy Code
 // Copy the text into a string object
String text = word.getText();
// Do something with the text.

getArea()

Gets the area or location on the page, in pixel units, of a given result element.

Copy Code
Rectangle area = word.getArea();

getConfidence()

Gets the confidence of a given result element.

Copy Code
int confidence = word.getConfidence();

getOrientation()

Gets the orientation of the result element.

Copy Code
int orientation = word.getOrientation();

  

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback